package com.mzj.saas.mservice.sys.controller;


import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.sys.service.PermissionService;
import com.mzj.saas.mservice.sys.vo.ParamVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 权限管理
 */
@Configuration
@Controller
@RequestMapping("/permission")
public class PermissionController {

    private static final Logger LOG = LoggerFactory.getLogger(PermissionController.class);

    @Autowired
    private PermissionService permissionService;

    /**
     * 获取用户权限
     *
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public ResultBean<List<Map<String, Object>>> getUserPermission(@RequestHeader String accessToken,@RequestParam(value = "communityHouseId",required = false) String communityHouseId) {
        return permissionService.getUserPermission(accessToken,communityHouseId);
    }

    /*
     *权限管理列表展示
     */
    @PostMapping(value = "/permissionManagerList")
    @ResponseBody
    public ResultBean<Object> permissionManagerList(@RequestHeader String accessToken) {
        return permissionService.permissionManagerList(accessToken);
    }

    /*
     *权限开关设置
     */
    @PostMapping(value = "/permissionOpenCloseButton")
    @ResponseBody
    public ResultBean<Object> permissionOpenCloseButton(@RequestHeader String accessToken, @RequestBody ParamVO paramVO) {
        return permissionService.permissionOpenCloseButton(accessToken, paramVO);
    }

    /*
     *角色的权限列表显示
     */
    @PostMapping(value = "rolePermissionList")
    @ResponseBody
    public ResultBean<Object> rolePermissionList(@RequestHeader String accessToken, @RequestParam(name = "roleId", required = false) Long roleId) {
        return permissionService.rolePermissionList(accessToken, roleId);
    }
}
